import { User, UserDao } from '../../utils/util'
Page({
  data: {
    images: [
      '/assets/images/haibao/1.jpg',
      '/assets/images/haibao/2.jpg',
      '/assets/images/haibao/3.jpg',
    ],
    books: []
  },
  onLoad() {

    UserDao.login(User.of('admin', 'admin'))
      .then(res => console.log(res))

    wx.showLoading({
      title: '正在加载中',
      complete: () => this.getGoods()
    })
  },
  getGoods() {
    wx.request({
      url: `${getApp<IAppOption>().globalData.baseURL}getHomeGoodsList`,
      method: 'GET',
      success: ({ data }) => {
        //@ts-ignore
        const { cxsj } = data.data
        //@ts-ignore
        const { mssk } = data.data
        //@ts-ignore
        const { rmjs } = data.data
        const books = [
          { 'name': '热门技术', 'value': rmjs },
          { 'name': '秒杀时刻', 'value': mssk },
          { 'name': '畅销书籍', 'value': cxsj }
        ]
        this.setData({
          // @ts-ignore
          books: books
        })
        wx.hideLoading()
      }
    })
  },
  gotoSearch() {
    wx.navigateTo({
      url: '../search/search',
    })
  },
  gotoMore(e: WechatMiniprogram.ControlTap) {
    const { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: `../goodsList/goodsList?id=${id}`,
    })
  }
})
